import cv2
import numpy as np

# =========== red =========== =========== =========== ===========
# h_min, h_max, s_min, s_max, v_min, v_max = 160, 179, 160, 255, 0, 255
# lower = np.array([h_min, s_min, v_min])
# upper = np.array([h_max, s_max, v_max])
# mask1 = cv2.inRange(imgHSV, lower, upper)
# h_min, h_max, s_min, s_max, v_min, v_max = 0, 10, 160, 255, 0, 255
# lower = np.array([h_min, s_min, v_min])
# upper = np.array([h_max, s_max, v_max])
# mask2 = cv2.inRange(imgHSV, lower, upper)
# mask = cv2.bitwise_or(mask1, mask2)
# =========== =========== =========== =========== =========== ===========

myColors = [
    [160, 179, 160, 255, 0, 255],
    [0, 10, 160, 255, 0, 255],
    [95, 114, 130, 255, 0, 255],
]


def findColor(img):
    imgHSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    for color in myColors:
        h_min, h_max, s_min, s_max, v_min, v_max = color
        lower = np.array([h_min, s_min, v_min])
        upper = np.array([h_max, s_max, v_max])
        mask = cv2.inRange(imgHSV, lower, upper)
        cv2.imshow(str(color), mask)


capture = cv2.VideoCapture(0)

while True:
    success, frame = capture.read()
    frame = cv2.flip(frame, 1)
    img = cv2.resize(frame, dsize=None, fx=0.5, fy=0.5)

    cv2.imshow("original", img)

    findColor(img)

    key = cv2.waitKey(1)
    if key == ord('q'):
        break

cv2.destroyAllWindows()
